var vue = new Vue({
    el: '#app',
    data:{
        loginForm : {},

        loginFormRules: {
            loginName: [
                {required: true, message: '请输入用户名'}
            ],
            password: [
                {required: true, message: '请输入密码'},
            ]
        },

        loginLoading : false,
        loginBtnMsg : '登  录',
    },
    created: function () {
        this.initPage();
    },
    methods: {
        login : function () {
            var self = this;
            self.$refs['loginForm'].validate(function (valid) {
                if (!valid)  return false;
                self.loginForm.password = hex_md5(self.loginForm.password).toUpperCase();
                $.ajax({
                    url: constant.ROOT_SITE + '/system/user/login',
                    data: JSON.stringify(self.loginForm),
                    success: function (result) {
                        if (result.code === 200) {
                            setCookie(constant.TOKEN_NAME,result.body.token);
                            localStorage.setItem(constant.USER_INFO,JSON.stringify(result.body));
                            top.location = constant.ROOT_SITE + "/home.html";
                        } else {
                            self.$message.error(result.errMsg);
                        }
                    }
                })

            });
        },
        //初始化页面跳转，为了防止从iframe跳转到login页面直接在iframe中显示login页面
        initPage : function() {
            if(window.top != window.self){
                top.location.href = location.href;
            }
        },
    }
});